import React, { Component } from 'react';
import { WeaOrgTree, WeaErrorPage } from 'ecCom';

class LeftOrgTree extends Component {
  constructor(props) {
    super(props);
    this.clickTree = this.clickTree.bind(this);
  }
  clickTree(t) {
    if (t && t.node && t.node.props) {
      const leftBtn = document.getElementsByClassName('wea-left-right-layout-btn');
      const { changeSubcompany } = this.props;
      if (changeSubcompany) {
        changeSubcompany(t.node.props);
      }
      leftBtn[0].click();
    }
  }
  render() {
    const params = {
      rightStr: 'Car:Maintenance',
    };
    return (
      <WeaOrgTree
        ecId={`${this && this.props && this.props.ecId || ''}_WeaOrgTree@airmj5`}
        treeNodeClick={this.clickTree}
        needSearch
        params={params}
      />
    );
  }
}

// 组件检错机制
class MyErrorHandler extends Component {
  render() {
	  const hasErrorMsg = this.props.error && this.props.error !== '';
	  return (
      <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@s8cqub`} msg={hasErrorMsg ? this.props.error : '对不起，该页面异常，请联系管理员！'} />
	  );
  }
}

export default LeftOrgTree;
